package com.hqyj.springBoot.modules.test.dao;

import com.hqyj.springBoot.modules.test.entity.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CountryDao {

    @Select("select * from test_country where country_id = #{countryId}")
    @Results(id = "countryResult",value = {
            @Result(column = "country_id",property = "countryId"),
            //sql查询的结果集和entity属性的映射关系
            @Result(
                    column = "country_id",
                    property = "cities",
                    javaType = List.class,
                    //one是一对一映射关系
                    //返回集合关系的映射定义,@Many的方法并传递column参数,将查询的结果集,映射给property属性
                    many = @Many(select = "com.hqyj.springBoot.modules.test.dao.CityDao.getCitiesByCountryId")
            )
    })
    Country getCountryByCountryId(int countryId);

}
